package com.erlang4j.api.process;

import com.erlang4j.api.IBinding;
import com.erlang4j.api.ISendMailBox;

/**
 * <p>
 * This corresponds closely to an Erlang process. For convenience it is also an mailbox. The mailbox can be accessed
 * even if the process is not alive.
 * <ul>
 * <li>Assuming that the process is alive, it has a list of message handlers and is receiving items from the mail box
 * and calling the appropriate message handler.
 * <li>The IProcess has a "matchingBinding" that is the current set of bindings that are included in the pattern
 * matching. bind() modifies this matchingBinding
 * </ul>
 * </p>
 * 
 * <p>
 * Design Notes
 * <ul>
 * <li>Note that the IProcess doesn't implement Thread. This interface exposes a much tighter set of methods.
 * <li>The process is returned by IErlang4j.spawn(). If no message adapters are given, there is no thread launched, but
 * the mail box still works
 * </ul>
 * </p>
 */
public interface IProcess extends ISendMailBox {

	/** is the process still alive */
	boolean isAlive();

	/** this politely asks the process to stop */
	void terminate();

	/**
	 * This is the binding that maintains the current state, that is included in working out whether the message
	 * handlers match
	 */
	IBinding matchingBinding();

	/**
	 * Modify the data in the matching bind for the next time a message is processed
	 */
	void bind(String key, Object object);

}
